<form id="formEdit" action="role/save" class="form-horizontal" role="form" >
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel">操作</h4>
            </div>
            <div class="modal-body">

            	<!-- 以下为要修改的的内容 -->

				<input type="hidden" name="id" data-th-value="${model.id}" id="modelId">
				<!-- <input type="hidden" name="parentId" th:value="${model.parent==null?null:model.parent.id}"> -->				
                <div class="form-group">
                	<label for="txt_parent" class="col-sm-2 control-label">上级菜单</label>
                	<div class="col-sm-9">
	                    <input name="parentId" data-th-value="${model.parent==null?null:model.parent.id}" class="form-control" id="txt_parent">
                	</div>
                </div>
                <div class="form-group">
                	<label for="txt_name" class="col-sm-2 control-label">名称</label>
                	<div class="col-sm-9">
	                    <input type="text" name="name" data-th-value="${model.name}" class="form-control" id="name">
                	</div>
                </div>
                <div class="form-group">
                	<label for="txt_url" class="col-sm-2 control-label">访问地址</label>
                    <div class="col-sm-9">
	                    <input type="text" name="url" data-th-value=${model.url} class="form-control" id="txt_url" placeholder="">
	                </div>
                </div>
                <div class="form-group">
                	<label for="txt_role" class="col-sm-2 control-label">权限</label>
                    <div class="col-sm-9">
	                    <!-- <input type="text" name="role.id" data-th-value="${model.role==null?'':model.role.id}" class="form-control" id="txt_role" placeholder="权限"> -->
	                    <select class="form-control" name="role" id="txt_role">
	                    	<option value="" style="display: none;"></option>
							<option th:each="role:${roles}" th:value="${role.id}" th:selected="${model.role!=null&&role.id==model.role.id}" th:text="${role.name}">abc</option>
						</select>
                    </div>
                </div>
                <div class="form-group">
                	<label for="txt_sort" class="col-sm-2 control-label">排序</label>
                    <div class="col-sm-9">
	                    <input type="text" name="idx1" data-th-value="${model.idx1}" class="form-control" id="txt_sort">
                    </div>
                </div>
                
                <div class="form-group">
                	<label for="txt_type" class="col-sm-2 control-label">主页种类</label>
                    <div class="col-sm-9">
	                    <!-- <input type="text" name="idx1" data-th-value="${model.idx1}" class="form-control" id="txt_type"> -->
	                    <select class="form-control selectpicker" name="type" id="txt_type">
	                    	<option value="" style="display: none;"></option>
							<option value="0" th:selected="${model.type==0}">管理员</option>
							<option value="1" th:selected="${model.type==1}">普通用户</option>
						</select>
                    </div>
                </div>
                <!-- 以上为要修改的内容 -->

            </div>
            <div class="modal-footer">
                <button type="submit" class="btn btn-primary"><span class="glyphicon glyphicon-floppy-disk" aria-hidden="true"></span>保存</button>
                <button type="button" class="btn btn-default" data-dismiss="modal"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span>关闭</button>
            </div>
        </div>
    </div>
</form>
<script type="text/javascript" th:inline="javascript">
 	var options= {
			message: '验证不通过',
			feedbackIcons: {
                 valid: 'glyphicon glyphicon-ok',
                 invalid: 'glyphicon glyphicon-remove',
                 validating: 'glyphicon glyphicon-refresh'
             },
             fields: { 

            	name: {
    				validators: {
    					notEmpty: {
    						message: '权限名称不能为空'
    					}
    				}
    			},
    			role:{
    				validators:{
    					notEmpty:{
    						message: '权限不能为空'
    					}
    				}
    			}
             	
             }
         };
        $('#formEdit').bootstrapValidator(options).on('success.form.bv', function(e) {
        	e.preventDefault();							   	//很重要没有它则会提交默认表单，不会做下面的ajax表单提交
            var fd = new FormData($("#formEdit")[0]); 
            $.ajax({  
              url: "menu/save",  
              type: "POST",  
              data: fd,  
              processData: false,  // 不处理数据  
              contentType: false,   // 不设置内容类型
              success:function(result){
            	  if(result.success){
	            	  $('#myModal').modal("hide");
            	  }else{
            		  bootbox.alert(result.msg);
            	  }
              },
              error:function(result){
            	  bootbox.alert(result.msg);
              }
            });  
    	});
   	/* var treeviewDefaultParams = {
		expandIcon: "glyphicon glyphicon-plus-sign",
	    collapseIcon: "glyphicon glyphicon-minus-sign",
		emptyIcon:"glyphicon glyphicon-file",
		showBorder:false,
		showTags: true,
		data:{}
	};
 */
	$(function(){
		$('#txt_parent').bootstrapCombotree({
			url:'menu/combotree?id='+$('#modelId').val()
		});
		
		$('.selectpicker').selectpicker({});
	});
	
	//在树的所有结点中找到id值的结点对象
	/* function getNode(root,id){
		for(var i=0;i<root.length;i++){
			var node=root[i];
			if(node.id==id){
				return node;
			}
			var x=getNode(root.nodes,id);
			if(x){
				return x;
			}
		}
		return null;
	} */
</script>